from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d, has_prize=True):
        super().__init__(d, has_prize)

    def get_name(self):
        return "小鸟爱飞翔"

    def game_alert(self):
        self.alert_close_by_file("./game/img/小鸟爱飞翔")

    def handle_main(self):
        self.log_msg("等待进入游戏页面")
        self.img_exit("./game/img/小鸟爱飞翔/game_main0.png", 100)
        self.log_msg("已进入游戏页面")
        self.game_alert()
        self.log_msg("点击开始游戏")
        self.img_click("./game/img/小鸟爱飞翔/go.png")
        self.log_msg("等待进入游戏主界面")
        self.img_exit("./game/img/小鸟爱飞翔/game_main.png", 100)
        self.log_msg("已进入游戏主界面")

        if self.not_prize_handle():
            return False
        
        self.game_alert()

        self.log_msg("点击十字")
        self.img_click("./game/img/小鸟爱飞翔/hide.png")
        self.img_click_if_exists('点击通天塔', "./game/img/小鸟爱飞翔/play.png", './game/img/小鸟爱飞翔/play01.png')

        while not self.check_done():
            self.log_msg("开始挑战")
            self.d.sleep(2)
            self.img_click_if_exists("点击挑战", "./game/img/小鸟爱飞翔/play01.png", "./game/img/小鸟爱飞翔/play03.png")
            self.img_click_if_exists("点击挑战", "./game/img/小鸟爱飞翔/play03.png", "./game/img/小鸟爱飞翔/play03.png")
            self.log_msg("点击挑战")
            self.img_click("./game/img/小鸟爱飞翔/play03.png")
            self.log_msg("等待挑战完成")
            self.alert_close("./game/img/小鸟爱飞翔/play02.png", 0, 10)
            self.log_msg("挑战完成")

        # self.d.sleep(2)
#        self.close_game()
